package com.vdg.data;

import android.content.Context;
import android.util.Log;

import com.vdg.util.Utilities;

public class SettingData {

	public static final String LOCK_TYPE_PASS_CODE = "lock_Type_pass_code";
	public static final String LOCK_TYPE_PATTERM = "lock_Type_pattern";

	private static final String PASS_CODE_SAVE_KEY = "pass_code_key";
	private static final String LOCK_TYPE_SAVE_KEY = "lock_Type";
	private static final String LOCK_SETTING_SAVE_KEY = "lock_setting_key";
	private static final String TIME_SETTING_SAVE_KEY = "time_setting";
	private static final String PATTERN_CODE_SAVE_KEY = "pattern_code";
	private static final String IS_REQUIRE_PASSWORD_SAVE_KEY = "is_require_password";
	private static final String TAG = "SettingData";

	public static enum LOCK_SETTING_TYPE {
		TIME, HOME, CLOSE_APP
	};

	public static enum LOCK_TYPE {
		PASS_CODE, LOCK_PATTERM, FAKE_FORCE_CLOSE
	};

	private String mPassCode;
	private LOCK_TYPE mLockType;
	private LOCK_SETTING_TYPE mLockSetting;
	private String mTimeSetting;
	private char[] mPatternCode;
	private boolean mIsRequirePassword = true;
	private static SettingData sInstance;

	public static SettingData getInstance(Context context) {
		if (sInstance == null) {
			sInstance = new SettingData();
		}
		sInstance.loadSetting(context);
		return sInstance;
	}

	public char[] getPatternCode() {
		return mPatternCode;
	}

	public void setPatternCode(char[] mPatternCode, Context context) {
		Utilities.saveStringToSharedPreferences(String.valueOf(mPatternCode),
				context, PATTERN_CODE_SAVE_KEY);
		this.mPatternCode = mPatternCode;
	}

	public LOCK_SETTING_TYPE getLockSetting() {
		return mLockSetting;
	}

	public void setLockSetting(LOCK_SETTING_TYPE mLockSetting, Context context) {
		Utilities.saveStringToSharedPreferences(mLockSetting.toString(),
				context, LOCK_SETTING_SAVE_KEY);
		this.mLockSetting = mLockSetting;
	}

	public LOCK_TYPE getLockType() {
		return mLockType;
	}

	public void setLockType(LOCK_TYPE mLockType, Context context) {
		Utilities.saveStringToSharedPreferences(mLockType.toString(), context,
				LOCK_TYPE_SAVE_KEY);
		this.mLockType = mLockType;
	}

	public void loadSetting(Context context) {
		mPassCode = Utilities.getStringFromSharedPreferences(
				PASS_CODE_SAVE_KEY, context);
		mTimeSetting = Utilities.getStringFromSharedPreferences(
				TIME_SETTING_SAVE_KEY, context);
		mPatternCode = Utilities.getStringFromSharedPreferences(
				PATTERN_CODE_SAVE_KEY, context).toCharArray();
		String locksetting = Utilities.getStringFromSharedPreferences(
				LOCK_SETTING_SAVE_KEY, context);
		String isRequirePassword = Utilities.getStringFromSharedPreferences(
				IS_REQUIRE_PASSWORD_SAVE_KEY, context);
		if (isRequirePassword != null && !isRequirePassword.equals("")
				&& isRequirePassword.equals(String.valueOf(false))) {
			mIsRequirePassword = false;
		} else {
			mIsRequirePassword = true;
		}
		if (locksetting != null && !locksetting.equals("")) {
			mLockSetting = LOCK_SETTING_TYPE.valueOf(locksetting);
		} else {
			mLockSetting = LOCK_SETTING_TYPE.HOME;
		}
		String lockType = Utilities.getStringFromSharedPreferences(
				LOCK_TYPE_SAVE_KEY, context);
		if (lockType != null && !lockType.equals("")) {
			mLockType = LOCK_TYPE.valueOf(lockType);
		} else {
			mLockType = LOCK_TYPE.PASS_CODE;
		}
	}

	public void setRequirePassword(boolean isRequire, Context context) {
		Utilities.saveStringToSharedPreferences(String.valueOf(isRequire),
				context, IS_REQUIRE_PASSWORD_SAVE_KEY);
		mIsRequirePassword = isRequire;
	}

	public String getTimeSetting() {
		return mTimeSetting;
	}

	public boolean getRequirePassword() {
		return mIsRequirePassword;
	}

	public void setTimeSetting(String mTimeSetting, Context context) {
		Utilities.saveStringToSharedPreferences(mTimeSetting, context,
				TIME_SETTING_SAVE_KEY);
		this.mTimeSetting = mTimeSetting;
	}

	public String getPassCode() {
		return mPassCode;
	}

	public void setPassCode(String mPassCode, Context context) {
		Utilities.saveStringToSharedPreferences(mPassCode, context,
				PASS_CODE_SAVE_KEY);
		this.mPassCode = mPassCode;
	}

}
